#include <private/qobject_p.h>
#include "ROSyncProperty.h"
#include "QQuickROData.h"
#include "ROHost.h"
#include "ROHelper.h"
#include "ROSignalConnection.h"



ROSyncProperty::ROSyncProperty(QObject *parent):ROSyncObject(parent)
{
    auto i = ROHelper::instance();
    setUpdater(i->triggered());
}

void ROSyncProperty::initialize()
{
    ROSyncObject::initialize();
}

void ROSyncProperty::validateUpdater()
{
    if(m_reg)
    {
        delete m_reg;
    }

    if(m_updater)
    {
        m_reg = m_updater->registerUpdater(this);
        m_reg->setParent(this);
    }
}

ROPropertyUpdater *ROSyncProperty::updater() const
{
    return m_updater;
}

void ROSyncProperty::setUpdater(ROPropertyUpdater *newUpdater)
{
    if (m_updater == newUpdater)
        return;
    m_updater = newUpdater;
    validateUpdater();
    emit updaterChanged();
}

void ROSyncProperty::updateAllProperty(bool safe)
{
    updateProperties(allProperties(),safe);
}

void ROSyncProperty::updateProperties(const QStringList &properties,bool safe)
{
    auto data = getROObjectData(this);
    data->host->onPropertyUpdate(this,properties,safe);
}

